
<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>必发彩票-下注</title>
    <script src="js/jquery-1.10.1.min.js"></script>
    <script src="js/md5.js"></script>
    <script src="js/layer.js"></script>
    <script src="js/public.js"></script>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
            text-decoration: none;
        }
        body,html{
            width: 100%;
            height: 100%;
            overflow: hidden;
            font-family: '微软雅黑';
        }
        .fl{
            float: left;
        }
        .fr{
            float: right;
        }
        .feng{
            width: 100%;
            height: 35px;
            line-height: 35px;
            text-align: center;
        }
        .feng span{
            color: #666;
            font-size: 14px;
            display: inline-block
        }
        .feng span#f-time{
            color: #fc3f05;
            margin-left: 10px
        }
        .beforeq{
            width: 100%;
            height: 35px;
            line-height: 35px;
            text-align: center;
            background:#f6dcdb
        }
        .beforeq span{
            display: inline-block;
            color: #666;
            font-size: 14px;
        }
        .beforeq span#s-hao{
            margin-left: 10px
        }
        .beforeq span#s-hao i{
            width: 25px;
            height: 25px;
            font-style: normal;
            display: inline-block;
            border-radius: 50%;
            background: #fc3f05;
            color: #fff;
            font-size: 12px;
            text-align: center;
            line-height: 25px;
            margin-right: 5px
        }
        .action-list{
            width: 100%;
            margin-top: 10px;
            min-height: 200px;
            max-height: 200px;
            overflow-y: scroll;
            margin-bottom: 10px;
        }
        .action-list li{
            font-size: 14px;
            color: #333;
            margin: 0 30px;
            height: 50px;
            list-style: none;
        }
        .action-list li .a-title ,.a-zhu , .a-money{
            margin-right: 50px;
        }
        .a-money{
            margin-right: 10px
        }
        .a-title{
            min-width: 150px;
        }
        .action-list li .a-title p,.a-zhu p, .a-money p{
            word-break:break-all; /* 支持IE和chrome，FF不支持*/
            word-wrap:break-word; /* 以上三个浏览器均支持 */
            margin-top: 5px
        }
        .action-list li .a-title p span.f-qi{
            color: #537CEF;
        }
        .a-zhu{
            min-width: 80px;
            max-width: 150px;
        }
        .a-zhu .a-odds{
            color: #fc3f05;
        }
        .a-money input{
            width: 60px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            border: none;
            background: #ecebf0;
            color: #333;
            display: inline-block;
            margin-right: 5px;
            margin-top: 10px
        }
        .a-close img{
            display: block;
            width: 20px;
            height: 20px;
            cursor: pointer;
            margin-top: 20px
        }
        .a-gai{  
            width: 100%;
            height: 30px;
            line-height: 30px;
            border-top: 1px solid #eee
        }
        .a-gai span{
            display: inline-block;
            font-size: 16px;
            cursor: pointer;
        }
        .a-gai span.a-cz{
            color: #fc3f05;
            margin-left: 20px;
        }
        .a-gai span.a-qd{
            color: #537CEF;
            margin-right: 20px;
        }
        .a-dan{
            width: 100%;
            height: 30px;
            line-height: 30px;
            border-top: 1px solid #eee;
            text-align: center;
        }
        .a-dan span{
            display: inline-block;
            font-size: 14px;
        }
        
        .a-dan span.a-heji{
            margin-left: 20px;
        }
        .a-dan span.a-heji i,.tatal{
            font-style: normal;
            color: #fc3f05;
        }
    </style>
</head>

<body>

    <div class="feng">
        <span class="f-qi" id="f-qi"></span>
        <span>期封盘</span>
        <span id="f-time"></span>
    </div>
    <div class="beforeq">
        <span id="s-qi"></span>
        <span>期</span>
        <span id="s-hao">
            
        </span>
    </div>
    <ul class="action-list">
        
    </ul>
    <div class="a-dan">
        <span>共</span>
        <span class="a-num"></span>
        <span>笔注单</span>
        <span class="a-heji">合计: <i>¥</i> </span>
        <span class="tatal"></span>
    </div>
    <div class="a-gai">
        <span class="a-cz fl">重置</span>
        <span class="a-qd fr">确定</span>
    </div>
<script src="js/public.js"></script>
<script>
 
    $(function(){
        var type = parent.$('#lotteryName').data('type');
        var buyObj = jsonObj;
        var uid = getCookie('uid');
        
        // 获取彩票信息
        action(type);
        var lotteryArr = parent.$('.content').data('content');

        var res = '';
        for(var i = 0,iL=lotteryArr.length;i<iL;i++){
            res += '<li>'+
                        '<div class="a-title fl">'+
                            '<p class="a-name"></p>'+
                            '<p><span class="f-qi"></span> 期</p>'+
                        '</div>'+
                        '<div class="a-zhu fl">'+
                            '<p class="a-content">'+lotteryArr[i].content+'</p>'+
                            '<p>@ <span class="a-odds">'+lotteryArr[i].odds+'</span></p>'+
                        '</div>'+
                        '<div class="a-money fl">'+
                            '<input type="text" value="'+lotteryArr[i].payPrice+'" data-val="'+i+'" class="input"> 元'+
                        '</div>'+
                        '<div class="a-close fr">'+
                            '<img src="images/close.png" data-index="'+i+'">'+
                        '</div>'+
                    '</li>'
        }
        $('.action-list').append(res)

        $('.a-close').click(function(){
            var index = $('img',this).data('index');
            $('.action-list li').eq(index).remove();
            lotteryArr.splice(index,1);
            total()
        })
        
        $('.input').on('blur',function(){
            
            var index = $(this).data('val')
            lotteryArr[index].payPrice =  Number($(this).val());
            total();
            console.log(lotteryArr)
        })
        
        // 计算注数和钱数
        function total(){
            var arry = [];
            for(var i = 0,iL=lotteryArr.length;i<iL;i++){
                arry.push(lotteryArr[i].payPrice)
            }

            $('.a-num').text(lotteryArr.length);
            $('.tatal').text(sum(arry));
        }

        total()
        
        // 计算数组的和
        function sum(arr) {
            var s = 0;
            for (var i=arr.length-1; i>=0; i--) {
                s += arr[i];
            }
            return s;
        }

        // 重置
        $('.a-cz').click(function(){
            $('.input').val(2);
            for(var i = 0,iL=lotteryArr.length;i<iL;i++){
                lotteryArr[i].payPrice = 2
            }
            total();
        })

        var index = parent.layer.getFrameIndex(window.name);//获取窗口索引
        // 提交
        $('.a-qd').click(function(){

            buyObj.uid = uid;
            buyObj.lotteryType = type;
            buyObj.issue = $('#f-qi').text();
            buyObj.payPrice = $('.tatal').text();
            buyObj.lotteryTickets = lotteryArr;
            buyObj.from = 'pc';
            
            $ajax(
                url+'buy_lottery',
                'post',
                buyObj,
                function(data){
                    
                    parent.layer.msg(data.msg,function(){
                        parent.layer.close(index);
                    });
                
                },
                function(data){
                    layer.msg(data.msg);
                }
            )
        })
        
        
    })


</script>
</body>

</html>
